﻿using ERP.Common.Util;
using ERP.Common.Util.Util.Controller;
using ERP.Common.Util.Util.Model;
using ERP.SYS.Interfaces;
using ERP.SYS.Model.Entity;
using Microsoft.AspNetCore.Mvc;

namespace ERP.SYS.Controller.Controllers;

[Route("api/[controller]")]
[ApiController]
public class UserController : BaseController<SysUser>
{
    public UserController(IUserService baseService) : base(baseService)
    {

    }

    [HttpGet("user/info")]
    public async Task<IActionResult> UserInfo()
    {
        string authorization = Request.Headers["Authorization"];
        Dictionary<string, object> data = JwtUtil.ParseJwtMetadata(authorization);
        int userId = int.Parse(data["id"].ToString());
        SysUser user = await ((IUserService)_baseService).UserInfo(userId);
        return Ok(RestResultBuilder<SysUser>.Success(user));
    }
}
